<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
function calculate() 
{
    var num = parseInt(document.getElementById("num").value, 10);
    var result = 0;
    for (var i = 0; i <= num; i++) 
    {
      result += i;
    }
    alert("合计值为" + result + "。");
}
</script>
</head>
<body>
输入数值:<input type="text" id="num">
<button onClick="calculate()">计算</button>
</body>
</html> 
